package com.smart.community.order.common.enums;

import com.smart.community.common.base.ex.ServiceException;
import com.smart.community.common.base.result.ResultStatus;
import lombok.Getter;

import java.util.stream.Stream;

/**
 * 支付  1   2  35
 *
 */
@Getter
public enum PlatFormEnum {
    /**
     * 浏览器
     */
    PLAT_FORM_PC(1, "10"),
    /**
     *
     */
    PLAT_FORM_IOS(2, "11"),

    /**
     *
     */
    PLAT_FORM_ANDROID(3, "12"), /*
     * 小程序
     */
    PLAT_FORM_APPLET(4, "13");

    private final int flag;
    private final String code;

    PlatFormEnum(int flag, String code) {
        this.flag = flag;
        this.code = code;
    }

    //        Lambda   Stream  Optional
    public static String of(int flag) {
        return Stream.of(values()).filter(platForm -> platForm.getFlag() == flag).findAny().orElseThrow(() -> new ServiceException(ResultStatus.SYS_ERROR)).getCode();
    }
}
